﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Middleware
{
    [Serializable]
    public class IOR
    {
        public int ObjectID { get; private set; }
        public string IP { get; private set; }
        public int Port { get; private set; }

        public IOR(int objectID, string ip, int port)
        {
            this.ObjectID = objectID;
            this.IP = ip;
            this.Port = port;
        }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            if (ReferenceEquals(this, obj)) return true;
            return obj.GetType() == typeof (IOR) && Equals((IOR) obj);
        }

        private bool Equals(IOR other)
        {
            if (ReferenceEquals(null, other)) return false;
            if (ReferenceEquals(this, other)) return true;
            return other.ObjectID == ObjectID && Equals(other.IP, IP) && other.Port == Port;
        }

        public override int GetHashCode()
        {
            unchecked
            {
                int result = ObjectID;
                result = (result*397) ^ (IP != null ? IP.GetHashCode() : 0);
                result = (result*397) ^ Port;
                return result;
            }
        }
    }
}
